/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package mrp.productionPlanning.session;

import java.util.ArrayList;
import java.util.List;
import javax.ejb.Stateless;
import javax.ejb.LocalBean;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;
import mrp.productionPlanning.entity.HolidayEntity;

/**
 *
 * @author Wei Haoyang
 */
@Stateless
@LocalBean
public class HolidaySessionBean {
    
    @PersistenceContext
    EntityManager em;

    // Add business logic below. (Right-click in editor and choose
    // "Insert Code > Add Business Method")
    public HolidayEntity getHolidayById(Long id){
        return em.find(HolidayEntity.class, id);
    }
    
    public List<HolidayEntity> getAllHolidays(){
        List<HolidayEntity> out = new ArrayList<HolidayEntity>();
        Query query = em.createQuery("SELECT u FROM HolidayEntity u");
        out = query.getResultList();
        return out;
    }
    
    public void addHolidayDay(HolidayEntity holiday){
        em.persist(holiday);
    }
    
    public void updateHoliday(HolidayEntity holiday){
        em.merge(holiday);
    }
    
    public void removeHoliday(HolidayEntity holiday){
        em.remove(holiday);
    }
}
